#include "date.h"

Date::Date(const int &p_year, const int &p_month, const int &p_day)
{
	year=p_year;
	month=p_month;
	day=p_day;
	if(!is_valid_date())
	{
		throw INVALID_DATE;
	}
}

bool Date::is_valid_date() const
{
	bool p_ok=false;
	p_ok=(1945<=get_year() && 2045>=get_year() && 1<=get_month() && 12>=get_month() && 1<=get_day() && get_days_in_month()>=get_day());
	return(p_ok);
}

bool Date::is_leap_year() const
{
	bool p_is_leap_year=false;
	if (((0==get_year()%4) && (0!=get_year()%100)) || (0==get_year()%400))
	{
		p_is_leap_year=true;
	}
	else
	{
		p_is_leap_year=false;
	}
	return(p_is_leap_year);
}

int Date::get_days_in_month() const
{
	int days_in_months[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	int days_in_month=0;
	if(is_leap_year() && 2==get_month())
	{
		days_in_month=29;
	}
	else
	{
		days_in_month=days_in_months[get_month()-1];
	}
	return(days_in_month);
}


int Date::get_year() const
{
	return(year);
}
		
int Date::get_month() const
{
	return(month);
}
		
int Date::get_day() const
{
	return(day);
}

